package com.ztesoft.book.api.controller.auth;

import com.ztesoft.book.common.utils.Result;
import com.ztesoft.book.common.utils.jwt.JwtUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author lzq.
 * @description h5认证接口
 * @date 2021-07-29 18:09
 */
@Slf4j
@RestController
@RequestMapping("/auth")
public class AuthController {

    /**
     * 方法功能描述:使用学号换取token以便后续访问接口
     *
     * @return Result
     *
     * @author YangFan
     * @date 2021-07-27 16:52
     */
    @PostMapping("/getTokenBySno")
    public Result getTokenBySno(String getTokenBySno) {
        try {

            String currentTimeMillis = String.valueOf(System.currentTimeMillis());
            String token = JwtUtil.signUserExt(getTokenBySno, currentTimeMillis);
            // 小程序用户信息入库或更新

            return Result.success(token);
        }
        catch (Exception e) {
            return Result.error("接口【getTokenBySno】调用异常:" + e.getMessage());
        }
    }
}
